home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / FilmWP (PL).ifs < prev    next >
Text File  |  2005-03-13  |  19KB  |  515 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=(c) 2004 îwistak
  8. Title=Film.WP (PL)
  9. Description=Movie importation script for Film.WP info by îwistak & picture by Goster
  10. Site=http://film.wp.pl
  11. Language=PL
  12. Version=1
  13. Requires=3.5.0
  14. Comments=Movie information & picture importation (Picture by Goster) partialy based on filmweb script by Piotr Kardasz, Adma's|14.02.2005 Improvements made by Adma's
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program FilmWP;
  23. var
  24.   MovieName, adres: string;
  25.   Link, id: string;
  26.  
  27. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  28.   var
  29.   i: Integer;
  30.   begin
  31.   result := -1;
  32.   if StartAt < 0 then
  33.     StartAt := 0;
  34.   for i := StartAt to List.Count-1 do
  35.     if Pos(Pattern, List.GetString(i)) <> 0 then
  36.       begin
  37.       result := i;
  38.       Break;
  39.       end;
  40.   end;
  41.  
  42. procedure DecodeHTML(var Value: String);
  43.   var
  44.   FullValue, CharCode: String;
  45.   Counter: Integer;
  46.   begin
  47.   if Value <> '' then begin
  48.     FullValue := '';
  49.     Counter := 1;
  50.     repeat
  51.       if StrGet(Value, Counter) <> '&' then
  52.         begin
  53.         CharCode := copy(Value, Counter, 1);
  54.         case CharCode of
  55.           '▒': CharCode := '╣';
  56.           '╢': CharCode := '£';
  57.           'í': CharCode := 'Ñ';
  58.           '╝': CharCode := 'ƒ';
  59.           'ª': CharCode := 'î';
  60.           '¼': CharCode := 'Å';
  61.           end;
  62.         FullValue := FullValue + CharCode;
  63.         Counter := Counter + 1;
  64.         end
  65.       else
  66.         begin
  67.         CharCode := copy(Value, Counter, 7);
  68.         case CharCode of
  69.           'ą': FullValue := FullValue + '╣';
  70.           'ć': FullValue := FullValue + 'µ';
  71.           'ę': FullValue := FullValue + 'Ω';
  72.           'ł': FullValue := FullValue + '│';
  73.           'ń': FullValue := FullValue + '±';
  74.           'ó': FullValue := FullValue + '≤';
  75.           'ś': FullValue := FullValue + '£';
  76.           'ź': FullValue := FullValue + 'ƒ';
  77.           'ż': FullValue := FullValue + '┐';
  78.           'Ą': FullValue := FullValue + 'Ñ';
  79.           'Ć': FullValue := FullValue + '╞';
  80.           'Ę': FullValue := FullValue + '╩';
  81.           'Ł': FullValue := FullValue + 'ú';
  82.           'Ń': FullValue := FullValue + '╤';
  83.           'Ó': FullValue := FullValue + '╙';
  84.           'Ś': FullValue := FullValue + 'î';
  85.           'Ź': FullValue := FullValue + 'Å';
  86.           'Ż': FullValue := FullValue + '»';
  87.           'Š': FullValue := FullValue + ' ';
  88.           'š': FullValue := FullValue + 'í';
  89.           'Ţ': FullValue := FullValue + 'í';
  90.           'ţ': FullValue := FullValue + 'ú';
  91.           'Ť': FullValue := FullValue + 'ñ';
  92.           'ť': FullValue := FullValue + 'Ñ';
  93.           'Ŧ': FullValue := FullValue + 'î';
  94.           'ŧ': FullValue := FullValue + 'º';
  95.           'Ũ': FullValue := FullValue + '¿';
  96.           'ũ': FullValue := FullValue + '⌐';
  97.           'Ű': FullValue := FullValue + '¬';
  98.           'ű': FullValue := FullValue + '½';
  99.           'Ų': FullValue := FullValue + '¼';
  100.           'ų': FullValue := FullValue + '¡';
  101.           'Ŵ': FullValue := FullValue + '«';
  102.           'ŵ': FullValue := FullValue + '»';
  103.           'Ŷ': FullValue := FullValue + '░';
  104.           'ŷ': FullValue := FullValue + '▒';
  105.           'Ÿ': FullValue := FullValue + '▓';
  106.           'ƀ': FullValue := FullValue + '┤';
  107.           'Ɓ': FullValue := FullValue + '╡';
  108.           'Ƃ': FullValue := FullValue + '╢';
  109.           'ƃ': FullValue := FullValue + '╖';
  110.           'Ƅ': FullValue := FullValue + '╕';
  111.           'ƅ': FullValue := FullValue + '╣';
  112.           'Ɔ': FullValue := FullValue + '║';
  113.           'Ƈ': FullValue := FullValue + '╗';
  114.           'ƈ': FullValue := FullValue + '╝';
  115.           'Ɖ': FullValue := FullValue + '╜';
  116.           'Ɛ': FullValue := FullValue + '╛';
  117.           'Ƒ': FullValue := FullValue + '┐';
  118.           'ƒ': FullValue := FullValue + '└';
  119.           'Ɠ': FullValue := FullValue + '┴';
  120.           'Ɣ': FullValue := FullValue + '┬';
  121.           'ƕ': FullValue := FullValue + '├';
  122.           'Ɩ': FullValue := FullValue + '─';
  123.           'Ɨ': FullValue := FullValue + '┼';
  124.           'Ƙ': FullValue := FullValue + '╞';
  125.           'ƙ': FullValue := FullValue + '╟';
  126.           'Ȁ': FullValue := FullValue + '╚';
  127.           'ȁ': FullValue := FullValue + '╔';
  128.           'Ȃ': FullValue := FullValue + '╩';
  129.           'ȃ': FullValue := FullValue + '╦';
  130.           'Ȅ': FullValue := FullValue + '╠';
  131.           'ȅ': FullValue := FullValue + '═';
  132.           'Ȇ': FullValue := FullValue + '╬';
  133.           'ȇ': FullValue := FullValue + '╧';
  134.           'Ȉ': FullValue := FullValue + '╨';
  135.           'ȉ': FullValue := FullValue + '╤';
  136.           'Ȑ': FullValue := FullValue + '╥';
  137.           'ȑ': FullValue := FullValue + '╙';
  138.           'Ȓ': FullValue := FullValue + '╘';
  139.           'ȓ': FullValue := FullValue + '╒';
  140.           'Ȕ': FullValue := FullValue + '╓';
  141.           'ȕ': FullValue := FullValue + '╫';
  142.           'Ȗ': FullValue := FullValue + '╪';
  143.           'ȗ': FullValue := FullValue + '┘';
  144.           'Ș': FullValue := FullValue + '┌';
  145.           'ș': FullValue := FullValue + '█';
  146.           'Ƞ': FullValue := FullValue + '▄';
  147.           'ȡ': FullValue := FullValue + '▌';
  148.           'Ȣ': FullValue := FullValue + '▐';
  149.           'ȣ': FullValue := FullValue + '▀';
  150.           'Ȥ': FullValue := FullValue + 'α';
  151.           'ȥ': FullValue := FullValue + 'ß';
  152.           'Ȧ': FullValue := FullValue + 'Γ';
  153.           'ȧ': FullValue := FullValue + 'π';
  154.           'Ȩ': FullValue := FullValue + 'Σ';
  155.           'ȩ': FullValue := FullValue + 'σ';
  156.           'Ȱ': FullValue := FullValue + 'µ';
  157.           'ȱ': FullValue := FullValue + 'τ';
  158.           'Ȳ': FullValue := FullValue + 'Φ';
  159.           'ȳ': FullValue := FullValue + 'Θ';
  160.           'ȴ': FullValue := FullValue + 'Ω';
  161.           'ȵ': FullValue := FullValue + 'δ';
  162.           'ȶ': FullValue := FullValue + '∞';
  163.           'ȷ': FullValue := FullValue + 'φ';
  164.           'ȸ': FullValue := FullValue + 'ε';
  165.           'ȹ': FullValue := FullValue + '∩';
  166.           'ɀ': FullValue := FullValue + '≡';
  167.           'Ɂ': FullValue := FullValue + '±';
  168.           'ɂ': FullValue := FullValue + '≥';
  169.           'Ƀ': FullValue := FullValue + '≤';
  170.           'Ʉ': FullValue := FullValue + '⌠';
  171.           'Ʌ': FullValue := FullValue + '⌡';
  172.           'Ɇ': FullValue := FullValue + '÷';
  173.           'ɇ': FullValue := FullValue + '≈';
  174.           'Ɉ': FullValue := FullValue + '°';
  175.           'ɉ': FullValue := FullValue + '∙';
  176.           'ɐ': FullValue := FullValue + '·';
  177.           'ɑ': FullValue := FullValue + '√';
  178.           'ɒ': FullValue := FullValue + 'ⁿ';
  179.           'ɓ': FullValue := FullValue + '²';
  180.           'ɔ': FullValue := FullValue + '■';
  181.           'ɕ': FullValue := FullValue + ' ';
  182.           '&#x%DF;': FullValue := FullValue + '▀';
  183.           '4': FullValue := FullValue + '"';
  184.           '–': FullValue := FullValue + '-';
  185.           '‘': FullValue := FullValue + '"';
  186.           '’': FullValue := FullValue + '"';
  187.           '“': FullValue := FullValue + '"';
  188.           '”': FullValue := FullValue + '"';
  189.           '„': FullValue := FullValue + '"';
  190.           else
  191.             FullValue := FullValue + CharCode;
  192.           end;
  193.         Counter := Counter + 7;
  194.       end;
  195.     until Counter > Length(Value);
  196.     HTMLDecode(FullValue);
  197.     Value := FullValue;
  198.     end
  199.   end;
  200.  
  201.  
  202. function extractLineText(Line: string; startToken: string; endToken: string): string;
  203.   var
  204.   StartPos: Integer;
  205.   token: string;
  206.   begin
  207.   StartPos := pos(startToken, Line) + Length(startToken);
  208.   Line := copy(Line, StartPos, Length(Line) - StartPos +1);
  209.   Line := copy(Line, 1, Pos(endToken, Line)-1);
  210.   HTMLRemoveTags(Line);
  211.   DecodeHTML(Line);
  212.   extractLineText := Trim(Line);
  213.   end;
  214.  
  215. function extractText(Page: TStringList; startToken: string; endToken: string; startPos: Integer): string;
  216.   var
  217.   Line: String;
  218.   begin
  219.   Line := copy(Page.Text, startPos, Length(Page.Text)-startPos);
  220.   StartPos := pos(startToken, Line);
  221.   if (StartPos > 0) then
  222.     begin
  223.     StartPos := pos(startToken, Line) + Length(startToken);
  224.     //aby zepewniµ obs│ugΩ przypadku, gdy endToken wystΩpuje tak┐e przed startToken
  225.     Line := copy(Line, StartPos, Length(Page.Text) - StartPos +1);
  226.     Line := copy(Line, 1, Pos(endToken, Line)-1);
  227.     HTMLRemoveTags(Line);
  228.     DecodeHTML(Line);
  229.     Line := Trim(Line);
  230.     Line := StringReplace(Line, #13#10, '');
  231.     end
  232.   else
  233.     Line := '';
  234.  
  235.   extractText := Line;
  236.   end;
  237.  
  238. function ExtractMovieAddress(Line: string): String ;
  239.   var
  240.   MovieAddress: string;
  241.   StartPos: Integer;
  242.   begin
  243.   StartPos := Pos('<a href=', Line);
  244.   if (StartPos > 0) then
  245.     begin
  246.     MovieAddress := copy(Line, StartPos, Length(Line)-StartPos);
  247.     MovieAddress := copy(MovieAddress, 10, Pos('">', MovieAddress)-10);
  248.     end;
  249.   extractMovieAddress := MovieAddress;
  250. end;
  251.  
  252. procedure AddMoviesTitles(Page: TStringList);
  253.   var
  254.   LineNr: Integer;
  255.   Line: string;
  256.   MovieTitle, MovieAddress: string;
  257.   StartPos: Integer;
  258.   begin
  259.   //NajczΩ£ciej szukane
  260.   LineNr := FindLine('szukane:', Page, 0);
  261.   if LineNr > -1 then
  262.   begin
  263.     PickTreeAdd('NajczΩ£ciej szukane:', '');
  264.     MovieTitle := extractLineText(Page.GetString(LineNr+16), '<i>', '</i>');
  265.     if (MovieTitle<>'') then
  266.       MovieTitle := ' (' + MovieTitle + ')';
  267.     MovieTitle := extractLineText(Page.GetString(LineNr+15), '<b>', '</a>')+MovieTitle;
  268.  
  269.     Line := Page.GetString(LineNr+15);
  270.     MovieAddress := extractMovieAddress(Line);
  271.     PickTreeAdd(MovieTitle, MovieAddress);
  272.  
  273.     //Znalezionych
  274.     LineNr := FindLine('Znalezionych:', Page, LineNr);
  275.     Line := Page.GetString(LineNr);
  276.     //Sprawdzamy ile WP znalaz│o pozycji
  277.     StartPos := pos('<b>', Line)+3;
  278.     Line := copy(Line, StartPos, pos('</b>', Line)-StartPos);
  279.     if (StrToInt(Line, 0)>1) then
  280.       begin
  281.       PickTreeAdd('Znalezione ('+Line+'):', '');
  282.       LineNr := LineNr+6;
  283.       repeat
  284.         Line := Page.GetString(LineNr);
  285.         if (pos('span class', Line)>0) then
  286.           begin
  287.           MovieTitle := extractLineText(Page.GetString(LineNr+1), '<i>', '</i>');
  288.           if (MovieTitle<>'') then
  289.             MovieTitle := ' (' + MovieTitle + ')';
  290.           MovieTitle := extractLineText(Page.GetString(LineNr), ' ', '</a>')+MovieTitle;
  291.           MovieAddress := ExtractMovieAddress(Line);
  292.           PickTreeAdd(MovieTitle, MovieAddress);
  293.           end
  294.         else if (pos('znalezione pozycje', Line)>0) then
  295.           begin
  296.           MovieAddress := ExtractMovieAddress(Line);
  297.           PickTreeAdd('Poka┐ wszystkie pozycje...' , MovieAddress);
  298.           end;        
  299.         LineNr := LineNr+1;
  300.       until Pos('</table>', Line) > 0;
  301.       end;
  302.     end;
  303.   end;
  304.  
  305. procedure AnalyzePage(Address: string; PostQuery: string);
  306.   var
  307.   Page: TStringList;
  308.   
  309.   begin
  310.   adres := address;
  311.   Page := TStringList.Create;
  312.   if (PostQuery <> '') then
  313.     Page.Text := PostPage(Address, PostQuery)
  314.   else
  315.     Page.Text := GetPage(Address);
  316.   Link := Address;
  317.   if pos('Podyskutuj na Forum', Page.Text) > 0 then
  318.     AnalyzeMoviePage(Page)
  319.   else if pos('Znalezionych:', Page.Text) > 0 then
  320.     begin
  321.     PickTreeClear;
  322.     AddMoviesTitles(Page);
  323.     if PickTreeExec(Address) then
  324.       AnalyzePage(Address, '');
  325.     end
  326.     else
  327.      begin
  328.      DecodeHTML(MovieName);
  329.      ShowMessage('Nie znaleziono ┐adnego filmu spe│niaj╣cego kryteria: "'+MovieName+'".');
  330.      end
  331.  
  332.   Page.Free;
  333.   end;
  334.  
  335. procedure AnalyzeMoviePage(Page: TStringList);
  336.   var
  337.   Line, Obsada, OrgLine, linia, tytul: string;
  338.   LineNr, licznik, pozycja, pozycja2: Integer;
  339.   StartPos, endPos: Integer;
  340.    stronka: TStringList;
  341.   
  342.   begin
  343.   // Tytu│ polski & Rok produkcji
  344.   Line := extractText(Page, '<b class="ti">', '</b>', 0);
  345.   //czasami wp dodaje rok produkcji do lini z tytu│em
  346.   StartPos := Pos('(', Line);
  347.   if (StartPos > 0) then
  348.     begin
  349.     SetField(fieldYear, Copy(Line, StartPos+1, 4));
  350.     Line := Copy(Line, 0, StartPos-1);
  351.     end
  352.   setField(fieldTranslatedTitle, Line);
  353.  
  354.   // Tytu│ oryginalny
  355.   Line := extractText(Page, '<i class="ti" id="gr">', '</i>', 0);
  356.   //czasami wp w linii, gdzie jest polski tytu│ umieszcza angielski, polskiego nie za│╣czaj╣c wog≤le...
  357.   if ((Pos('<i class="ti" id="gr">', Page.Text) > Pos('Tw≤rcy:', Page.Text)) or (Line = '')) then
  358.     begin
  359.     Line := getField(fieldTranslatedTitle);
  360.     setField(fieldTranslatedTitle, '');
  361.     end
  362.   setField(fieldOriginalTitle, Line);
  363.  
  364.   // Kategoria
  365.   setField(fieldCategory, extractText(Page, '<b>Gatunek:</b>', '<br>', 0));
  366.  
  367.   // Kraj
  368.   setField(fieldCountry, extractText(Page, '<b>Kraj:</b>', '<br>', 0));
  369.   
  370.   // Czas trwania
  371.   setField(fieldLength, extractText(Page, '<b>Czas trwania:</b>', 'min', 0));
  372.  
  373.   // Rok produkcji
  374. //  Line := extractText(Page, '<b>Premiera kinowa:</b>', '<br>', 0);
  375. //  Line := copy(Line, 1, 4);
  376. //  SetField(fieldYear, Line);
  377.  
  378.   // Ocena
  379.   Line := extractText(Page, 'Ocena internaut≤w:', '</b>', 0);
  380.   if (Line <> '') then
  381.     SetField(fieldRating, IntToStr(Round(StrToFloat(Line))));
  382.  
  383.   // Producent
  384.   //brak
  385.  
  386.   // Re┐yseria
  387.   SetField(fieldDirector, extractText(Page, '<b>Re┐yseria:</b>', '<br>', 0));
  388.  
  389.   // Obsada
  390.   LineNr := FindLine('<b>Obsada:</b>', Page, 0)+1;
  391.   if (LineNr>0) then
  392.     begin
  393.     Obsada := '';
  394.     Line := Page.GetString(LineNr);
  395.     while (Pos('<div align="right">', Line) = 0) do
  396.       begin
  397.       if (Obsada<>'') then
  398.         Obsada := Obsada + ', ';
  399.       HTMLRemoveTags(Line);
  400.       DecodeHTML(Line);
  401.       if (Pos('..... ', Line) > 0) then
  402.         begin
  403.         Line := StringReplace(Line, '..... ', '(jako ');
  404.         Line := Line + ')';
  405.         end;
  406.       Obsada := Obsada + Line;
  407.       LineNr := LineNr+1;
  408.       Line := Page.GetString(LineNr);
  409.       end;
  410.     SetField(fieldActors, Obsada);
  411.     end;
  412.  
  413.   // Czas trwania
  414.   //brak
  415.  
  416.   // Opis filmu
  417.   StartPos := Pos('<b class="ti" id="or">Opis:</b>', Page.Text);
  418.   if (StartPos > 0) then
  419.     SetField(fieldDescription, extractText(Page, '<span id="mi">', '</span>', StartPos));
  420.  
  421.   //Komentarze
  422.   StartPos := Pos('<b class="ti" id="or">Recenzje:', Page.Text);
  423.   //czasami zamiast 'Recenzje' jest 'Opinie'
  424.   if (StartPos = 0) then
  425.     StartPos := Pos('<b class="ti" id="or">Opinie:', Page.Text);
  426.  // if (StartPos > 0) then
  427.    // SetField(fieldComments, extractText(Page, '<span id="mi">', '</span>', StartPos));
  428.  
  429.   //URL
  430.   setField(fieldURL, Link);
  431.   
  432.   //Foto 
  433.   //pobranie strony z galeri╣
  434.   stronka := TStringList.Create;
  435.   startPos := pos('id=', adres);
  436.   endPos := pos('&h=', adres);
  437.   id := copy(adres, startPos + 3, endPos - startPos - 3);
  438.   link := 'http://film.wp.pl/film_foto.html?id=' + id + '&m=plakat';
  439.   stronka.Text := GetPage(link);
  440.   PickTreeClear;
  441.   PickTreeAdd('Wybierz ZdjΩcie','');
  442.   licznik := 0;
  443.   pozycja := FindLine('<img src="http://film.wp.pl/f/foto/small/', stronka, 0);
  444.   pozycja2 := FindLine('galeria: ', stronka, pozycja + 1);
  445.   repeat
  446.    begin
  447.    linia := stronka.GetString(pozycja);
  448.    startPos := pos('<img src="http://film.wp.pl/f/foto/small/', linia);
  449.    if (startPos <> 0) then
  450.    begin
  451.     delete(linia, 1, startPos + 9);
  452.     endPos := pos('.gif"', linia);
  453.     tytul := copy(linia, 1, endPos + 3); 
  454.     licznik := licznik + 1;
  455.     tytul := StringReplace(tytul, 'small/', '');
  456.     tytul := StringReplace(tytul, 'gif', 'jpg');
  457.     adres := tytul;
  458.     startPos := pos('alt="', linia);
  459.     delete(linia, 1, startPos + 4);
  460.     endPos := pos('">', linia);
  461.     tytul := copy(linia, 1, endPos - 1); 
  462.     PickTreeAdd(IntToStr(licznik) + tytul, adres);
  463.     end;
  464.    pozycja := pozycja + 1;
  465.    end;
  466.   until (pozycja >= pozycja2);
  467.   if licznik > 1 then
  468.    begin
  469.    if PickTreeExec(adres) then
  470.     GetPicture(adres);
  471.    end;
  472.   if licznik = 1 then 
  473.    GetPicture(adres);  
  474.   stronka.Free;
  475.  
  476.  
  477.   //DisplayResults;
  478.   end;
  479.  
  480. begin
  481.   if CheckVersion(3,5,0) then
  482.     begin
  483.     MovieName := GetField(fieldOriginalTitle);
  484.     if MovieName = '' then
  485.       MovieName := GetField(fieldTranslatedTitle);
  486.     if Input('FilmWP Import', 'Podaj tytu│ filmu:', MovieName) then
  487.       begin
  488.       // Zamiana na ISO-8859-2
  489.       MovieName:=StringReplace(MovieName, '╣', chr(177));
  490.       MovieName:=StringReplace(MovieName, 'µ', chr(230));
  491.       MovieName:=StringReplace(MovieName, 'Ω', chr(234));
  492.       MovieName:=StringReplace(MovieName, '│', chr(179));
  493.       MovieName:=StringReplace(MovieName, '±', chr(241));
  494.       MovieName:=StringReplace(MovieName, '≤', chr(243));
  495.       MovieName:=StringReplace(MovieName, '£', chr(182));
  496.       MovieName:=StringReplace(MovieName, 'ƒ', chr(188));
  497.       MovieName:=StringReplace(MovieName, '┐', chr(191));
  498.       MovieName:=StringReplace(MovieName, 'Ñ', chr(161));
  499.       MovieName:=StringReplace(MovieName, '╞', chr(198));
  500.       MovieName:=StringReplace(MovieName, '╩', chr(202));
  501.       MovieName:=StringReplace(MovieName, 'ú', chr(163));
  502.       MovieName:=StringReplace(MovieName, '╤', chr(209));
  503.       MovieName:=StringReplace(MovieName, '╙', chr(211));
  504.       MovieName:=StringReplace(MovieName, 'î', chr(166));
  505.       MovieName:=StringReplace(MovieName, 'Å', chr(172));
  506.       MovieName:=StringReplace(MovieName, '»', chr(175));
  507.       AnalyzePage('http://film.wp.pl/p/szukaj.html', 'fromBox=1&szukaj='+MovieName+'&lista=a0');
  508.       end;
  509.     end
  510.   else
  511.     ShowMessage('Skrypt wymaga programu Ant Movie Catalog w wersji 3.5.0 lub nowszej');
  512. end.
  513.  
  514.  
  515.